﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Ue.Infrastructure.RepositoryFramework;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain;
using Ue.Qcdz.Domain.SaleCategorys;
using Ue.Qcdz.Domain.SaleInfos;

namespace Ue.Qcdz.UI.Controls.SaleInfo
{
    public class SaleInfoProProduct : SkinnedGridView
    {
        private string skinFileName = "/Themes/zh-cn/Skins/Shop/Shop_Index_ProductList.ascx";
        #region Overrides of SkinnedControl

        protected override string GetSkinFileName()
        {
            return skinFileName;
        }

        #endregion

        #region Overrides of SkinnedGridView

        protected override void GridViewDataBind(object sender, EventArgs args)
        {
            IList<Ue.Qcdz.Domain.SaleInfos.SaleInfo> saleInfos;
            if (!string.IsNullOrEmpty(SiteContext.GetSiteContext().ShopId))
            {
                //按商铺ID获取
                string shopId = SiteContext.GetSiteContext().ShopId;
                ISaleInfoRepository repository =
                    RepositoryFactory.GetRepository
                        <ISaleInfoRepository, Ue.Qcdz.Domain.SaleInfos.SaleInfo>();
                saleInfos = repository.FindBy(shopId);

            }
            else if (!string.IsNullOrEmpty(SiteContext.GetSiteContext().CategoryId))
            {
                //按产品分类别获取
                string ctId = SiteContext.GetSiteContext().CategoryId;
                SaleCategory category = SaleCategoryService.GetSaleCategory(new System.Guid(ctId));
                ISaleInfoRepository repository =
                    RepositoryFactory.GetRepository
                        <ISaleInfoRepository, Ue.Qcdz.Domain.SaleInfos.SaleInfo>();
                saleInfos = repository.FindBy(category);

            }
            else
            {
                MessageWindow.RenderMessage("参数错误", "/default.aspx");
                return;
            }
            Repeater repeater = sender as Repeater;
            this.RecordCount = saleInfos.Count;
            repeater.DataSource = saleInfos;
            repeater.DataBind();

        }



        #endregion
    }
}
